package com.winit.openapi.wh.builder;

import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.inbound.vo.InboundDispatchinfoVo;
import com.winit.openapi.util.DateUtil;
import com.winit.openapi.util.ValidateUtil;

/**
 * 海外仓入库单 提货验货构造器
 * 
 * @version <pre>
 * Author     Version       Date        Changes
 * dinghua.an   1.0         2015年11月10日     Created
 *
 * </pre>
 * @since 1.
 */
public class InboundPickupBuilder {

    /**
     * build 验货/提货信息
     * 
     * @param json
     * @return
     */
    public static InboundDispatchinfoVo buildInspectionPickUp(JSONObject json) {
        InboundDispatchinfoVo inboundDispatchinfoVo = new InboundDispatchinfoVo();
        if (json.containsKey("orderNo")) {
            inboundDispatchinfoVo.setOrderNo(json.getString("orderNo").trim());
        }
        if (json.containsKey("pickupType")) {
            inboundDispatchinfoVo.setPickupType(json.getString("pickupType").trim());
        }else {
            inboundDispatchinfoVo.setPickupType("");
        }
        if (json.containsKey("inspectionType")){
            inboundDispatchinfoVo.setInspectionType(json.getString("inspectionType").trim());
        }
        if(json.containsKey("date") && ValidateUtil.isNotNull(json, "date")){
            String[] dates = json.get("date").toString().split("\\|");
            inboundDispatchinfoVo.setExpectFromDate(DateUtil.parse2Date(dates[0],DateUtil.FULL_DATE_STRING));
            inboundDispatchinfoVo.setExpectToDate(DateUtil.parse2Date(dates[1],DateUtil.FULL_DATE_STRING));
        }else if(json.containsKey("formatDate") && ValidateUtil.isNotNull(json, "formatDate")){
            String[] dates = json.get("formatDate").toString().split("\\|");
            inboundDispatchinfoVo.setExpectFromDate(DateUtil.parse2Date(dates[0],DateUtil.FULL_DATE_STRING));
            inboundDispatchinfoVo.setExpectToDate(DateUtil.parse2Date(dates[1],DateUtil.FULL_DATE_STRING));
        } else if (json.containsKey("dateExpectFrom") && json.containsKey("dateExpectTo")) {
            inboundDispatchinfoVo.setExpectFromDate(DateUtil.parse2Date(json.getString("dateExpectFrom"),DateUtil.FULL_DATE_STRING));
            inboundDispatchinfoVo.setExpectToDate(DateUtil.parse2Date(json.getString("dateExpectTo"),DateUtil.FULL_DATE_STRING));
        }
        if (json.containsKey("addressCode")) {
            inboundDispatchinfoVo.setAddressCode(json.getString("addressCode").trim());
        }else {
            inboundDispatchinfoVo.setAddressCode("");
        }
        if (json.containsKey("expressVendorCode")) {
            inboundDispatchinfoVo.setExpressVendorCode(json.getString("expressVendorCode"));
        }else {
            inboundDispatchinfoVo.setExpressVendorCode("");
        }
        if (json.containsKey("expressVendorName")) {
            inboundDispatchinfoVo.setExpressVendorName(json.getString("expressVendorName"));
        }else {
            inboundDispatchinfoVo.setExpressVendorName("");
        }
        if (json.containsKey("expressNo")) {
            inboundDispatchinfoVo.setExpressNo(json.getString("expressNo").trim());
        }else {
            inboundDispatchinfoVo.setExpressNo("");
        }
        if (json.containsKey("advanceBookingTime")) {
            inboundDispatchinfoVo.setAdvanceBookingTime(json.getBigDecimal("advanceBookingTime"));
        }
        return inboundDispatchinfoVo;
    }

}
